home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 Christmas / macformat-045.iso / Shareware Plus / Developers / NGL1.5.0E(fat)DEMO / Cel & Rotate Sample(PPC) / Cel & Rotate Sample(PPC).c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-19  |  3.2 KB  |  172 lines  |  [TEXT/CWIE]

  1. /*============================================================
  2.  
  3.                     Cel & Rotate sample program
  4.                     
  5. ============================================================*/
  6.  
  7. #include    "N_Library.h"
  8.  
  9. WindowPtr     CreateWindow         (Str255 name);
  10.  
  11.  
  12. #define        WindowSizeX        640
  13. #define        WindowSizeY        480
  14.  
  15. short        NewWindowX;
  16. short        NewWindowY;
  17.  
  18. short        Data_Rsrc = 0;
  19.  
  20. long        total_step = 0;
  21. long        wait;
  22. short        i,r=0;
  23. short        x[128];
  24. short        y[128];
  25. short        sp[128];
  26.  
  27. void main(void)
  28. {
  29.     WindowPtr    window;
  30.  
  31.  
  32.     ToolboxInit();
  33.     ColorCheck();
  34.     HideMenuBar();
  35.     window = CreateWindow("\pN Game Library <Cel & Rotate Sample>");
  36.     N_Window_Set(window,NewWindowX,NewWindowY,WindowSizeX,WindowSizeY);
  37.     Open_Resource_File(128,1,&Data_Rsrc);
  38.     N_Sp_Make(640,480);                                                //setup for sprite
  39.     N_Cel_Make(240000);                                                //setup for cel
  40.     HideCursor();
  41.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);
  42.     N_Sprite_Set(200,0,32,32,0,1,1,1);                                    //set Sprite 0(rotation mode)
  43.     N_Sprite_Set(201,1,32,32,0,1,1,0);                                    //set Sprite 1
  44.     N_Sprite_Set(202,2,32,32,0,1,1,0);                                    //set sprite 2
  45.     N_Pict_Draw(130,0,0,(GrafPtr)Main_Window,true);    
  46.     Delay(120,&wait);
  47.     Close_Resource_File(&Data_Rsrc);
  48.  
  49.     for (i=0;i!=128;i++)                                                    //make random position
  50.     {
  51.         x[i] = GetRandom(0,640);
  52.         y[i] = GetRandom(0,480+240)-120;
  53.         sp[i] = GetRandom(1,5)*2;
  54.     }
  55.  
  56.     do
  57.     {
  58.         total_step++;
  59.  
  60.         N_Sp_Put(0x80000000+1,(long)GetRandom(0,640)/32*32,(long)GetRandom(0,480)/32*32);    //draw background 
  61.         N_Sp_Put(0x80000000+2,(long)GetRandom(0,640)/32*32,(long)GetRandom(0,480)/32*32);
  62.  
  63.         if (total_step<128)                                                //move
  64.         {
  65.             for (i=0;i!=100;i++)
  66.             {
  67.     
  68.     
  69.                 N_Cel_Put(i,0x80000000,x[i],y[i]);
  70.     
  71.                 x[i] = x[i] + sp[i];
  72.  
  73.                 if (x[i]>640)
  74.                 {
  75.                     x[i] = -64;
  76.                     y[i] = GetRandom(0,480+240)-120;
  77.                 }
  78.             }
  79.         }
  80.  
  81.         if (total_step>=128 && total_step<256)                                //rotation
  82.         {
  83.             for (i=0;i!=100;i++)
  84.             {
  85.     
  86.  
  87.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);    
  88.  
  89.             }
  90.             r-=8;
  91.         }
  92.  
  93.         if (total_step>=256 && total_step<384)                                //rotation & move 1
  94.         {
  95.             for (i=0;i!=100;i++)
  96.             {
  97.     
  98.  
  99.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);
  100.  
  101.                 x[i] = x[i] + sp[i];
  102.  
  103.                 if (x[i]>640)
  104.                 {
  105.                     x[i] = -64;
  106.                     y[i] = GetRandom(0,480+240)-120;
  107.                 }
  108.     
  109.             }
  110.             r+=8;
  111.         }
  112.  
  113.         if (total_step>=384 && total_step<512)                                //rotation & move 2
  114.         {
  115.             for (i=0;i!=100;i++)
  116.             {
  117.     
  118.     
  119.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+16,y[i]+16,r);
  120.     
  121.                 x[i] = x[i] + sp[i];
  122.                 
  123.                 if (x[i]>640)
  124.                 {
  125.                     x[i] = -64;
  126.                     y[i] = GetRandom(0,480+240)-120;
  127.                 }
  128.             }
  129.  
  130.             r-=16;
  131.         }
  132.  
  133.  
  134.         if (total_step == 511)
  135.         {
  136.             total_step =0;
  137.             r = 0;
  138.         }
  139.         
  140.         N_Cel_Loop(0,0);
  141.     }
  142.         while (!Button());
  143.  
  144.         ShowMenuBar();
  145.         ShowCursor();
  146.         ColorRevert();
  147. }
  148.  
  149.  
  150.  
  151. WindowPtr CreateWindow (Str255 name)
  152. {
  153.     WindowPtr    window;
  154.     short        centerX,centerY;
  155.     short        windowWidth,windowHeight;
  156.  
  157.  
  158.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  159.     centerX  = (qd.screenBits.bounds.right -qd.screenBits.bounds.left)/2;
  160.     centerY  = (qd.screenBits.bounds.bottom -qd.screenBits.bounds.top)/2;
  161.     SetWTitle(window,name);
  162.     MoveWindow(window,NewWindowX=centerX-(WindowSizeX/2),NewWindowY=centerY-(WindowSizeY/2),false);
  163.     SizeWindow(window,WindowSizeX,WindowSizeY,TRUE);
  164.  
  165.     ShowWindow(window);
  166.     SetPort((GrafPtr)window );
  167.     return (WindowPtr)window;
  168. }
  169.     
  170.  
  171.  
  172.